package com.alm.handle.service.impl;

import com.alm.common.utils.StringUtils;
import com.alm.handle.core.domain.entity.SysDevCommand;
import com.alm.handle.mapper.SysDevCommandMapper;
import com.alm.handle.service.ISysDevCommandService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SysDevCommandServiceImpl implements ISysDevCommandService {

    @Resource
    private SysDevCommandMapper devCommandMapper;

    @Override
    public List<SysDevCommand> findListAll( Integer devType,Integer linenumber) {
        QueryWrapper<SysDevCommand> queryWrapper = new QueryWrapper<>();
        queryWrapper.select(
                "`id`",
                "`name`",
                "`type`",
                "`command`",
                "`group`",
                "`dev_type`",
                "`add_time`",
                "`remark`",
                "`update_time`");
        if(linenumber!=null&&linenumber>1){
            if (StringUtils.isNotNull(devType)) {
                queryWrapper.eq("type",4);
            }
        }else {
            if (StringUtils.isNotNull(devType)) {
                queryWrapper.apply("type = ( SELECT dev_parent_type from " +
                        " alm_dev_type_child WHERE dev_type = {0} limit 1 )",devType);
            }
        }
        return devCommandMapper.selectList(queryWrapper);
    }

    @Override
    public SysDevCommand findByid(Integer id) {
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("id",id);
        return devCommandMapper.selectOne(queryWrapper);
    }
}
